package edu.webarchitechture.bank.ejb3.services;

import edu.webarchitechture.bank.ejb3.domain.Customer;
import edu.webarchitechture.bank.ejb3.exception.CustomerNotFoundException;

import javax.ejb.Stateless;
import javax.persistence.PersistenceContext;
import java.security.InvalidParameterException;
import java.util.List;

import org.hibernate.Session;

/**
 * Bean implementation for the CustomerManager.
 *
 * @author Inoka Dissanayaka. 
 */
@Stateless
public class CustomerManagerBean implements CustomerManager {
    @PersistenceContext
    Session session;
    
    public Long createCustomer(Customer customer) throws InvalidParameterException {
        return getCustomerManagerDAO().createCustomer(customer);
    }

    public List<Customer> getCustomersOfAccount(Long accountId) throws InvalidParameterException {
        return getCustomerManagerDAO().getCustomersOfAccount(accountId);
    }

    public List<Customer> getCustomersOfLastName(String lastName) throws InvalidParameterException {
        return getCustomerManagerDAO().getCustomersOfLastName(lastName);
    }

    public Customer getCustomer(Long customerId) throws CustomerNotFoundException, InvalidParameterException {
        return getCustomerManagerDAO().getCustomer(customerId);
    }

    public void removeCustomer(Long customerId) throws CustomerNotFoundException, InvalidParameterException {
        getCustomerManagerDAO().removeCustomer(customerId);
    }

    public void setAddress(String street, String city, String state, String zip, String phone, String email, Long customerId) throws CustomerNotFoundException, InvalidParameterException {
        getCustomerManagerDAO().setAddress(street, city, state, zip, phone, email, customerId);
    }

    public void setName(String lastName, String firstName, String middleInitial, Long customerId) throws CustomerNotFoundException, InvalidParameterException {
        getCustomerManagerDAO().setName(lastName, firstName, middleInitial, customerId);
    }

    public CustomerManagerDAO getCustomerManagerDAO() {
        return new CustomerManagerDAO(session);
    }
}
